﻿@{
    Layout = "~/Views/Shared/_Layout_List.cshtml";
}
@section CSS{

}

<div class="wrapper animated fadeInUp" ng-controller="BackgroundJobListController">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>任务管理</h5>
                </div>

                <div class="ibox-title">
                    <div class="ibox-tools" style="display: inline-block; float: left">
                        <a href="javascript:void(0)" class="btn btn-danger  btn-xs btn-delete">删除</a>
                    </div>

                    <div class="ibox-tools" style="display: inline-block; float: right">
                        <a href="javascript:void(0)" data-title="任务创建" class="btn btn-primary btn-xs btn-creat-job">任务创建</a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form role="form" class="form-inline query-container" id="form_search">

                        <div class="form-group  m-l">
                            <label for="ClassTaskId" class="sr  m-r-xs">名称</label>
                            <input type="text" id="Name" name="Name" class="form-control" ng-model="model.Name">
                        </div>

                        <button class="btn btn-primary btn-search" type="button">搜索</button>
                    </form>
                    <div class="jqGrid_wrapper">
                        <table id="data_grid"></table>
                        <div id="grid_pager_bar"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section JS{
    <script src="/Scripts/controllers/backgroundjob.controller.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.btn-creat-job').click(function () {
                oUtils.showIframe({
                    areaWidth: '700px',
                    areaHeight: '530px',
                    Url: '/BackgroundJob/Add',
                    title: '后台任务创建',
                    beforeClose: function (index) {
                        if (index > 0) {
                            if (parent != null) {
                                var opt_is_success = parent.layer.getChildFrame('#opt_is_success', index).val();
                                if (opt_is_success && typeof (opt_is_success) != 'undefined' && opt_is_success == 'true') {
                                    $('#data_grid').trigger("reloadGrid");
                                }
                            }
                        }
                    }
                });
            });

            $('.btn-delete').click(function () {
                var idList = $('#data_grid').jqGrid('getGridParam', 'selarrrow');
                if (idList != null && idList != '' && idList.length > 0) {
                    if (confirm('确定要删除所选择的行吗？')) {
                        $.post('/BackgroundJob/Delete', { idList: idList.join(',') }, function (result) {
                            if (result.success) {
                                alert('删除成功');
                                $('#data_grid').trigger("reloadGrid");
                            } else {
                                alert(result.message || '操作失败');
                            }
                        }, 'json');
                    }
                } else {
                    alert('请勾选要操作的行 ');
                }
            })
        })


        function ShowEditFrame(BackgroundJobId) {
            oUtils.showIframe({
                areaWidth: '700px',
                areaHeight: '530px',
                Url: '/BackgroundJob/Info?BackgroundJobId=' + BackgroundJobId + '&r=' + Math.random(),
                title: '后台任务编辑',
                beforeClose: function (index) {
                    if (index > 0) {
                        if (parent != null) {
                            var opt_is_success = parent.layer.getChildFrame('#opt_is_success', index).val();
                            if (opt_is_success && typeof (opt_is_success) != 'undefined' && opt_is_success == 'true') {
                                $('#data_grid').trigger("reloadGrid");
                            }
                        }
                    }
                }
            });
        }


        function SetState(Id, State) {
            if (confirm('确定要修改当前任务的状态吗？')) {
                $.post('/BackgroundJob/UpdateState', { BackgroundJobId: Id, State: State }, function (result) {
                    if (result.success) {
                        $('#data_grid').trigger("reloadGrid");
                    } else {
                        alert(result.message || '操作失败');
                    }
                }, 'json');
            }
        }
    </script>
}


